home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-19 | 5.4 KB | 218 lines | [TEXT/MPCC] |
- // File Object Handler for the WASTE Text Engine
- // by Michael F. Kamprath, kamprath@earthlink.net
- //
- // v1.0, 12 March 1995
- //
-
- #include <Icons.h>
- #include <Drag.h>
- #include <LowMem.h>
- #include "Waste.h"
-
- #include "WE_hfs_Handler.h"
- #include "WASTE_Objects.h"
- #include "GetFileIcon.h"
- #include "SendFinderOpen.h"
-
- // Local Functions
- static void SizeHFSObject( Point *objectSize, HFSFlavor **theHFS );
-
- //
- // New Object Handler for HFS Objects
- //
- pascal OSErr HandleNewHFS(Point *defaultObjectSize,WEObjectReference objectRef)
- {
- HFSFlavor **theHFS = (HFSFlavor**)WEGetObjectDataHandle(objectRef);
-
- // First size the object as WASTE requires
- SizeHFSObject( defaultObjectSize, theHFS);
-
- // Set the object refcon to 0. This is for safety
- // as later we use the refcon to store the icon handle
- // for this object.
- WESetObjectRefCon( objectRef, nil );
-
- return(noErr);
- }
-
- //
- // Dispose Object handler for HFS Objects
- //
- pascal OSErr HandleDisposeHFS(WEObjectReference objectRef )
- {
- Handle theHFS = WEGetObjectDataHandle(objectRef);
- Handle iconCache = (Handle)WEGetObjectRefCon( objectRef );
-
- // If the object has an icon handle loaded, dispose of it.
- if (iconCache != nil)
- {
- DisposeIconSuite( iconCache, true );
- }
-
- // Dispos of the HFS data
- DisposHandle(theHFS);
-
- return(MemError());
- }
-
- //
- // Draw Object Handler for HFS objects
- //
-
- pascal OSErr HandleDrawHFS(Rect *destRect, WEObjectReference objectRef )
- {
- HFSFlavor **theHFS = (HFSFlavor**)WEGetObjectDataHandle(objectRef);
- Handle iconCache = (Handle)WEGetObjectRefCon( objectRef );
- FontInfo fInfo;
- GrafPtr thePort;
- Rect iconRect;
- OSErr iErr;
- short oldTextFont, oldTextSize, oldTextFace;
- short sysTextFont = LMGetSysFontFam();
- short sysTextSize = LMGetSysFontSize();
-
- // if the object's refcon did not contain an icon handle, load one.
- if (iconCache == nil)
- {
- HLockHi( (Handle)theHFS );
- if ( ((*theHFS)->fileCreator=='MACS')&&((*theHFS)->fileType=='fold') )
- iErr = GetIconSuite(&iconCache,genericFolderIconResource,svAllAvailableData);
- else
- {
- iErr = GetFileIcon( &(*theHFS)->fileSpec, svAllAvailableData, &iconCache );
-
- // iErr = NewDesktopIconSuite( (*theHFS)->fileSpec.vRefNum, (*theHFS)->fileCreator,
- // (*theHFS)->fileType, &iconCache);
- if (iErr)
- iErr = GetIconSuite(&iconCache,genericDocumentIconResource,svAllAvailableData);
- }
- HUnlock( (Handle)theHFS );
- if (iErr)
- return(iErr);
- WESetObjectRefCon( objectRef, (long)iconCache );
- }
-
- // Determine the icon's rectangle and plot it
- SetRect( &iconRect, (destRect->right + destRect->left)/2 - 16, destRect->top,
- (destRect->right + destRect->left)/2 + 16, destRect->top + 32 );
- iErr = PlotIconSuite(&iconRect,(IconAlignmentType)(atVerticalCenter + atHorizontalCenter),
- (IconTransformType)ttNone, iconCache);
-
- // Draw the file's title. First save old font info for port.
- GetPort(&thePort);
- oldTextFont = thePort->txFont;
- oldTextSize = thePort->txSize;
- oldTextFace = thePort->txFace;
-
- TextFont( sysTextFont );
- TextSize( sysTextSize );
- TextFace( 0 );
- GetFontInfo(&fInfo);
-
- MoveTo( destRect->left + 1, destRect->bottom - fInfo.descent - fInfo.leading );
- DrawString( (*theHFS)->fileSpec.name );
-
- TextFont( oldTextFont );
- TextSize( oldTextSize );
- TextFace( oldTextFace );
-
- return( iErr );
- }
-
- //
- // Click Handler for HFS Objects.
- // Will send the finder an open selection apple event when object is clicked.
- //
-
- static long oldHFSClickTime = nil;
-
- pascal OSErr HandleClickHFS( Point hitPt,
- short modifiers,
- long clickTime,
- WEObjectReference objectRef)
- {
- HFSFlavor **theHFS = (HFSFlavor**)WEGetObjectDataHandle(objectRef);
- OSErr iErr = noErr;
-
-
-
- if (oldHFSClickTime + GetDblTime() > clickTime )
- {
- HLockHi( (Handle)theHFS );
- iErr = SendFinderOpenAE(&(*theHFS)->fileSpec);
- HUnlock( (Handle)theHFS );
- }
-
- oldHFSClickTime = clickTime;
- return( iErr );
- }
-
- //
- // SizeHFSObject()
- // Used to return the display size of an HFS object
- //
- static void SizeHFSObject( Point *objectSize, HFSFlavor **theHFS )
- {
- FontInfo fInfo;
- GrafPtr thePort;
- short oldTextFont, oldTextSize, oldTextFace;
- short strWidth, strHeight;
- short sysTextFont = LMGetSysFontFam();
- short sysTextSize = LMGetSysFontSize();
-
- GetPort(&thePort);
- oldTextFont = thePort->txFont;
- oldTextSize = thePort->txSize;
- oldTextFace = thePort->txFace;
-
- TextFont( sysTextFont );
- TextSize( sysTextSize );
- TextFace( 0 );
-
- strWidth = StringWidth( (*theHFS)->fileSpec.name ) + 4;
- GetFontInfo(&fInfo);
- strHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
-
- TextFont( oldTextFont );
- TextSize( oldTextSize );
- TextFace( oldTextFace );
-
- objectSize->h = ( strWidth > 32 ) ? strWidth : 32 ;
- objectSize->v = 32 + strHeight + 1;
- }
-
- //
- // InsertFileRefFromFSSpec()
- // Inserts a file object into a WASTE instance.
- //
-
- OSErr InsertFileRefFromFSSpec( FSSpec *theFile, WEHandle theWE )
- {
- FInfo fndrInfo;
- HFSFlavor **theHFS;
- Point corner = {32,32};
- OSErr iErr;
-
- theHFS = (HFSFlavor**)NewHandleClear( sizeof(HFSFlavor) );
- if (theHFS)
- {
- // First construct the HFSFlavor object from the FSSpec
- iErr = FSpGetFInfo(theFile,&fndrInfo);
- if (iErr)
- {
- DisposHandle( (Handle)theHFS );
- return(iErr);
- }
- HLock( (Handle)theHFS );
- (*theHFS)->fileType = fndrInfo.fdType;
- (*theHFS)->fileCreator = fndrInfo.fdCreator;
- (*theHFS)->fdFlags = fndrInfo.fdFlags;
- (*theHFS)->fileSpec = (*theFile);
- HUnlock( (Handle)theHFS );
-
- // Now insert it into the WEHandle
- WEInsertObject( flavorTypeHFS, (Handle)theHFS, corner, theWE );
- }
- return(noErr);
- }
-